﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security;
using CoyoEden.Web.Data;
using System.Web;
using System.Security.Principal;

namespace CoyoEden.Web.Controller
{
	/// <summary>
	/// BFBase
	/// </summary>
	public class ControllerBase
	{
		public static void ResolveException(Exception ex,out FeedbackData msg) {
			msg = new FeedbackData();
			msg.IsOk = false;
			Type exType=ex.GetType();
			if (exType == typeof(SecurityException)) { 
				//not authorized
				msg.Body = ex.Message;
			}
			else if (exType == typeof(InvalidOperationException)) { 
				//business object's broken rules.
				msg.Body = ex.Message;
			}
			else if (exType == typeof(InvalidCastException))
			{
				//data invalid
				msg.Body = String.Format("数据格式有误：{0}", ex.Message);
			}
			else { 
				//unkown exception
				//TODO:Log unkown exception to file
				msg.Body = "应用程序发生错误";
			}			
		}
		/// <summary>
		/// Get Current User
		/// </summary>
		/// <returns></returns>
		public static IPrincipal GetCurrentUser() {
			var user = HttpContext.Current.User;
			return user;
		}
	}
}
